#include"check_login.h"
#include"Upload_database.h"
#include"list.h"
#include"sys_log.h"
//检查登录
int check_login1(USE* data)
{
	int flag = 0;
	MYSQL* ckconnect = NULL;
	ckconnect = connect_mysql();

	USE* head = NULL;
	head = List_init();
	head = read_mysql_to_list(ckconnect, head);	//读取完应该拿head接收链表
	printf("从MySQL中拿到的管理员链表的数据：\n");
	Printf_list(head);



	//接下来比较链表和输入的账号密码是否一致
	flag = while_check_login(head, data);

	return flag;
	freeLink(head);
	mysql_close(ckconnect);
}
//遍历链表检查输入是否正确
int while_check_login(USE* head,USE* data)
{
	int flag = 0;
	USE* p = head;
	while (p != NULL)
	{
		if (strcmp(p->user_name, data->user_name) == 0 && strcmp(p->user_password, data->user_password) == 0)
		{
			printf("管理员登录成功！\n");
			flag = 1;
			return flag;
		}
		p = p->Next;
	}
	if (flag == 0)
	{
		printf("账号或密码错误,管理员登录失败！\n");
		return flag;
	}
	return flag;
}










//检查用户登录
int check_login2(USE* data)
{
	int flag = 0;
	MYSQL* ckconnect = NULL;
	ckconnect = connect_mysql();

	USE* head = NULL;
	head = List_init();
	head = read_mysql_to_list2(ckconnect, head);	//读取完应该拿head接收链表
	printf("从MySQL中拿到的用户链表的数据：\n");
	Printf_list(head);



	//接下来比较链表和输入的账号密码是否一致
	flag = while_check_login(head, data);

	return flag;
	freeLink(head);
	mysql_close(ckconnect);
}
//遍历用户链表检查输入是否正确
int while_check_login2(USE* head, USE* data)
{
	int flag = 0;
	USE* p = head;
	while (p != NULL)
	{
		if (strcmp(p->user_name, data->user_name) == 0 && strcmp(p->user_password, data->user_password) == 0)
		{
			printf("用户登录成功！\n");
			flag = 1;
			return flag;
		}
		p = p->Next;
	}
	if (flag == 0)
	{
		printf("账号或密码错误,用户登录失败！\n");
		return flag;
	}
	return flag;
}
